/* 
 * @(#)Request.java 2012-5-2
 * Copyright (c) 2012
 * Dark-J (Zh)Co., Ltd.
 * Dark-J R&D,BeiJing
 *
 * All Rights Reserved
 * 
 * Revision History:
 * 								Modification	 Traking
 * Author (Email ID)			Date			 Number				Description
 * ----------------------------------------------------------------------------------
 * yongchong.bai				2012-5-2		 					Initial Version
 */

package com.jworktogether.application2;

import java.io.InputStream; 
import java.io.IOException; 
import java.io.BufferedReader; 
import java.io.UnsupportedEncodingException; 
import java.util.Enumeration; 
import java.util.Locale; 
import java.util.Map; 
import javax.servlet.RequestDispatcher; 
import javax.servlet.ServletInputStream; 
import javax.servlet.ServletRequest; 
 

/**
 * @author baiyc
 * @version 1.0
 */
public class Request implements ServletRequest { 
 
   private InputStream input; 
   private String uri; 
 
   public Request(InputStream input){ 
     this.input = input;    } 
 
   public String getUri() { 
     return uri; 
   } 
 
   private String parseUri(String requestString) { 
     int index1, index2; 
     index1 = requestString.indexOf(' '); 
     if (index1 != -1) { 
       index2 = requestString.indexOf(' ', index1 + 1); 
       if (index2 > index1) 
         return requestString.substring(index1 + 1, index2); 
     } 
     return null; 
   } 
 
   public void parse() { 
     // Read a set of characters from the socket 
     StringBuffer request = new StringBuffer(2048); 
     int i; 
     byte[] buffer = new byte[2048]; 
     try { 
       i = input.read(buffer); 
     } 
     catch (IOException e) { 
       e.printStackTrace(); 
       i = -1; 
     } 
     for (int j=0; j<i; j++) { 
       request.append((char) buffer[j]); 
     } 
     System.out.print(request.toString()); 
     uri = parseUri(request.toString()); 
   } 
 
   /* implementation of ServletRequest */ 
   public Object getAttribute(String attribute) { 
     return null; 
   } 
   public Enumeration getAttributeNames() { 
     return null; 
   } 
   public String getRealPath(String path) {      return null; 
   } 
   public RequestDispatcher getRequestDispatcher(String path) { 
     return null; 
   } 
   public boolean isSecure() { 
     return false; 
   } 
   public String getCharacterEncoding() { 
     return null; 
   } 
   public int getContentLength() { 
     return 0; 
   } 
 
   public String getContentType() { 
     return null; 
   } 
   public ServletInputStream getInputStream() throws IOException { 
     return null; 
   } 
   public Locale getLocale() { 
     return null; 
   } 
   public Enumeration getLocales() { 
     return null; 
   } 
   public String getParameter(String name) { 
     return null; 
   } 
   public Map getParameterMap() { 
     return null; 
   } 
   public Enumeration getParameterNames() { 
     return null; 
   } 
   public String[] getParameterValues(String parameter) { 
     return null; 
   } 
   public String getProtocol() { 
     return null; 
   } 
   public BufferedReader getReader() throws IOException { 
     return null;    } 
   public String getRemoteAddr() { 
     return null; 
   } 
   public String getRemoteHost() { 
     return null; 
   } 
   public String getScheme() { 
     return null; 
   } 
   public String getServerName() { 
     return null; 
   } 
   public int getServerPort() { 
     return 0; 
   } 
   public void removeAttribute(String attribute) {  } 
   public void setAttribute(String key, Object value) {  } 
   public void setCharacterEncoding(String encoding) 
     throws UnsupportedEncodingException {  }

/* (non-Javadoc)
 * @see javax.servlet.ServletRequest#getLocalAddr()
 */
@Override
public String getLocalAddr() {
	// TODO Auto-generated method stub
	return null;
}

/* (non-Javadoc)
 * @see javax.servlet.ServletRequest#getLocalName()
 */
@Override
public String getLocalName() {
	// TODO Auto-generated method stub
	return null;
}

/* (non-Javadoc)
 * @see javax.servlet.ServletRequest#getLocalPort()
 */
@Override
public int getLocalPort() {
	// TODO Auto-generated method stub
	return 0;
}

/* (non-Javadoc)
 * @see javax.servlet.ServletRequest#getRemotePort()
 */
@Override
public int getRemotePort() {
	// TODO Auto-generated method stub
	return 0;
} 
} 

